//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    coupons:[]
  },
  onLoad: function () {
    var that = this;
    wx.hideShareMenu()
    if (app.globalData.iphone == true) { that.setData({ iphone: 'iphone' }) }
  },
  onShow : function () {
    this.getMyCoupons();
  },
  // 获取优惠券
  getMyCoupons: function () {
    var that = this;
    app.get('coupon/get_coupons?Valid=all&CustId=' + app.globalData.uid, res => {
      console.log(res)
      if( res.code == 0 ){
        var coupons = res.result;
        if (coupons.length > 0) {
          that.setData({
            coupons,
            loadingMoreHidden: true
          });
        }
        }else{
          that.setData({
            loadingMoreHidden: false
          });
        }
    })
    // wx.request({
    //   url: app.globalData.urls + '/discounts/my',
    //   data: {
    //     token: app.globalData.token,
    //     status: 0
    //   },
    //   success: function (res) {
    //     if (res.data.code == 0) {
    //       var coupons = res.data.data;
    //       if (coupons.length > 0) {
    //         that.setData({
    //           coupons: coupons,
    //           loadingMoreHidden: true
    //         });
    //       }
    //     }else{
    //       that.setData({
    //         loadingMoreHidden: false
    //       });
    //     }
    //   }
    // })
  },
  goBuy:function(){
    wx.navigateTo({
      url: '/pages/coupons/coupons'
    })
  },
  gohome: function () {
    wx.switchTab({
      url: "/pages/index/index"
    })
  }

})
